package cz.cvut.fit.bugtrac.dao;

import com.google.appengine.api.datastore.Key;

import cz.cvut.fit.bugtrac.exception.BugTracException;
import cz.cvut.fit.bugtrac.persistence.AbstractBugTracEntity;

/**
 *  interface for data access object
 *  
 * @author Jaroslav Crhonek
 * 
 * @param <T>
 */
public interface BugTracDAO<T extends AbstractBugTracEntity> {
	
	/**
	 * Find the entity by ID or throw Exception if not found.
	 * 
	 * @param id
	 *            ID of entity.
	 * @return Entity with given ID.
	 * @throws BugTracException 
	 */
	T getById(Key id) throws BugTracException;

	/**
	 * Persist entity into the database.
	 * 
	 * @param entity
	 *            Entity to persist.
	 */
	void save(T entity);


	/**
	 * Refresh the entity with the latest state in DB.
	 * 
	 * @param entity
	 *            Entity to refresh.
	 */
	void refresh(T entity);

	/**
	 * This will delete the entity.
	 * 
	 * @param entity
	 *            Entity to delete.
	 */
	void delete(T entity);

	/**
	 * Clear the persistence context, causing all managed * entities to become detached.
	 */
	void clear();

	/**
	 * Merge the detached entity to attache it back to session.
	 * 
	 * @param entity
	 * @throws PerthException
	 */
	T merge(T entity);


}
